
function topbar(){
	window.onscroll=function(){
		var titlebar=$(".titlebar");
		var b=$('body');
		if(window.scrollY>130){
			titlebar.addClass('titlebar-fixtop');
			b.css({'padding-top':'50px'});
		}else{
			titlebar.removeClass('titlebar-fixtop');
			b.css({'padding-top':'0'});
		}
	}
}

var pope={
	init:function(options){
		if($('#storelist').text()=='')
			pope.storelist()
		$.each(options,function(index, el) {
			pope.action(el)
			
		});
	},
	action:function(obj){
		var pop=obj.find('.pop');
		var img=obj.find('.img-circle');
		obj.mouseenter(function(event) {	
			img.animate({top:'10px',width: '60px',height: '60px'});
			
			pop.stop(true,true).fadeIn();
		}).mouseleave(function(event) {
			img.stop(true,true).animate({top:'0',width: '35px',height: '35px'});
			pop.stop(true,true).fadeOut();
			
		});
		
	
	},
	storelist:function(){
		
			$.ajax({
	 			url: '/store/list',
	 			type: 'POST',
	 			 dataType: 'JSON'
	 		})
	 		.done(function(v) {
	 			$('.badge').text(v.total)
	 			$('#storelist').empty();
	 			if(v.data!=null){
	 				$('#storelist').append('<div class="popertitle"><h5><b>收藏书架</b></h5></div>')
	 				$.each(v.data, function(index, d) {
	 					$('#storelist').append('<a href="/cartoon/'+d.id+'"><img class="col-xs-5" src="'+d.pic+'" /></a>')
	 					.append('<div class="caption"><a href="/cartoon/'+d.id+'" class=""><h5>'+d.name+'</h5></a>')
	 					.append('<p class="grey el">'+d.msg+'<br/>更至<a class="active">&nbsp;66话</a><br/>')
	 					.append('<span class="glyphicon glyphicon-fire  active"></span>&nbsp;'+d.score+'</p></div>')
			 		});
	 				$('#storelist').append('<a href="/store" class="text-center"><h5 class="active">浏览更多>>></h5></a>')
	 			}
	 		})
		
	}
}




var modal={
	action:function(){
		
		
		$('#mymodal').on('show.bs.modal', function (e) {
			$('.navbar').css('margin-right', '10px');
			$('.titlebar-fixtop').css('padding-right', '10px');
			$('input[type=text]').val('');
			$('input[type=password]').val('');
			$(".form-group").attr('class','form-group')
			$('.help-block').empty();
			$('#loginerror').empty();
		});

		$('#mymodal').on('hidden.bs.modal', function (e) {
			$('.navbar').css('margin-right', '0');
			$('.titlebar-fixtop').css('padding-right', '0');
		});
		$('#Lsub').click(function(){
			var data=new FormData(document.getElementById('loginbox'));
			if(!$('#Lsub').hasClass('disabled')){
				$.ajax({
		 			url: '/user/login',
		 			type: 'POST',
		 			data: data,
		 			 dataType: 'JSON',  
		             cache: false,  
		             processData: false,  
		             contentType: false  
		 		})
		 		.done(function(d) {
		 			if(d.code==200){
		 				$('#mymodal').modal('hide')
		 				location.reload() 
		 			}else if(d.code==404){
		 				$('#loginerror').text('用户名或密码错误')
		 			}
		 		})
			}
			
	 		return false
		})
		return this;
	}
}

